package com.burgeon.backend.SHOP.rest;
/**
 * openid搜索会员数据
 */

import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.HashMap;

public class Submit extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public Submit(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     *
     * @return
     */

    public String  getData(String id,String table) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(id,table), url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");
        if (!"0".equals(code)) {
           throw new Exception(message);
        }

        return message.substring(0,15);
    }

    private MultiValueMap Data(String id,String table) {
        HashMap params = new HashMap();

        params.put("ID", id);
        params.put("table", table);//表名

        return DATA("ObjectSubmit", params, account, password);
    }

    public static void main(String[] args) {
        Submit g = new Submit("39.99.239.133:55321","nea@burgeon.com.cn","burgeon55321");
        try {
            System.err.println(g.getData("72","YC_RETAIL"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
